﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ERPStudio;
using System.Data.SqlClient;
using System.Reflection;
using System.Diagnostics;
using System.Threading;
using System.IO;

namespace ResUma
{
    public partial class PersonalFrm : FrmCard
    {
        // Factor for zoom the image
        private float zoomFac = 2;
        //set Zoom allowed
        private bool zoomSet = true;

        //value for moving the image in X direction
        private float translateX = 0;
        //value for moving the image in Y direction
        private float translateY = 0;

        //Flag to set the moving operation set
        private bool translateSet = false;
        //Flag to set mouse down on the image
        private bool translate = false;

        //set on the mouse down to know from where moving starts
        private float transStartX;
        private float transStartY;

        //Current Image position after moving 
        private float curImageX = 0;
        private float curImageY = 0;


        //temporary storage in bitmap
        Image bmp;

        float ratio;
        float translateRatio;



        private Int16 AnulCurent = 0;
        private Int16 LunaCurenta = 0;
        private Boolean FolosesteContracte = true;
        private Boolean FolosesteSituatieMilitara = false;
        private int IDOcupatieImplicita = 0;
        private int IDTipContractImplicit = 0;
        private int IDTipGradImplicit = 0;
        private int IDCasaAsigurariSanatateImplicit = 0;
        private int IDDepartamentImplicit = 0;
        private int LuniSuspendare = 0;
        private Int32 PersoanaSelectata = -1;
        public PersonalFrm(ModuleClass mInfo,Int32 _psel)
            : base(mInfo)
        {
            PersoanaSelectata = _psel;
            //AllowDelete = false;
            InitializeComponent();

          
            Binding bindDP1 = new System.Windows.Forms.Binding("Value", this.situatieMilitaraBindingSource, "DataScoatereEvidenta", true);
            bindDP1.Format += new ConvertEventHandler(bind_Format);
            this.dataScoatereEvidentaDTP.DataBindings.Add(bindDP1);
            Binding bindDP2 = new System.Windows.Forms.Binding("Value", this.persoaneBindingSource, "DataPlecarii", true);
            bindDP2.Format += new ConvertEventHandler(bind_Format);
            this.dataPlecariiDTP.DataBindings.Add(bindDP2);

            Binding bindDP3 = new System.Windows.Forms.Binding("Value", this.fKAngajatiSalarizarePersoaneBindingSource, "PanaLaData", true);
            bindDP3.Format += new ConvertEventHandler(bind_Format);
            this.panaLaDataAngajatDTP.DataBindings.Add(bindDP3);

            angajatiSalarizareTableAdapter.Adapter.RowUpdated += Adapter_RowUpdated;

            dataNasteriiDTP.Format = DateTimePickerFormat.Custom;
            dataNasteriiDTP.CustomFormat = "dd.MM.yyyy";
            dataElibAIDTP.Format = DateTimePickerFormat.Custom;
            dataElibAIDTP.CustomFormat = "dd.MM.yyyy";
            dataContractAngajatDTP.Format = DateTimePickerFormat.Custom;
            dataContractAngajatDTP.CustomFormat = "dd.MM.yyyy";


            dataScoatereEvidentaDTP.Format = DateTimePickerFormat.Custom;
            dataScoatereEvidentaDTP.CustomFormat = "dd.MM.yyyy";
            dataLuatEvidentaDTP.Format = DateTimePickerFormat.Custom;
            dataLuatEvidentaDTP.CustomFormat = "dd.MM.yyyy";

            dataVechimeMuncaDTP.Format = DateTimePickerFormat.Custom;
            dataVechimeMuncaDTP.CustomFormat = "dd.MM.yyyy";
            dataPlecariiDTP.Format = DateTimePickerFormat.Custom;
            dataPlecariiDTP.CustomFormat = "dd.MM.yyyy";

  
            workConnString = ModuleInfo.workConnectionString;
            lstPK.Add(numePrenumeTB);

            ////deocamdata nu e functional
            
            //angajatiSalarizareDGV.m_AutoCompletionColumns.Add(departamentColumn);
            //angajatiSalarizareDGV.m_AutoCompletionColumns.Add(gradColumn);
            angajatiOcupatiiDGV.m_AutoCompletionColumns.Add(ocupatieColumn);


            sexSursaBindingSource.List.Add(new SexSursa("Barbatesc", 0, ""));
            sexSursaBindingSource.List.Add(new SexSursa("Feminin", 1, ""));
            sexSursaBindingSource1.List.Add(new SexSursa("Carte Identitate", 0, ""));
            sexSursaBindingSource1.List.Add(new SexSursa("Buletin de Identitate", 1, ""));
            sexSursaBindingSource1.List.Add(new SexSursa("Pasaport", 2, ""));
            sexSursaBindingSource1.List.Add(new SexSursa("Certificat de Nastere", 3, ""));
            numeMacheta = Text;
            eSRPDataSet.ContracteMunca.DataColumn.DefaultValue = DateTime.Now;
            eSRPDataSet.ContracteMunca.CodUnitateColumn.DefaultValue = ModuleInfo.CodUnitate;
            MoveOnlyFirst = true;
            this.eSRPDataSet.Persoane.DataElibAIColumn.DefaultValue = DateTime.Now;
            this.eSRPDataSet.Persoane.NrFileCMColumn.DefaultValue = 1;
            this.eSRPDataSet.Persoane.CodUnitateColumn.DefaultValue = ModuleInfo.CodUnitate;
            this.eSRPDataSet.Persoane.PozCutieCMColumn.DefaultValue = 0;
            this.eSRPDataSet.Persoane.DataVechimeMuncaColumn.DefaultValue = DateTime.Now;
            this.eSRPDataSet.Persoane.UserIDColumn.DefaultValue = ModuleInfo.UserID;
            this.eSRPDataSet.Persoane.MarcaColumn.DefaultValue = "FARA";
            this.eSRPDataSet.Persoane.IdCasaAsigSanatateColumn.DefaultValue = 0;
            this.eSRPDataSet.Persoane.IdTipStudiiColumn.DefaultValue = 0;
            this.eSRPDataSet.Persoane.PlatesteCASColumn.DefaultValue = true;
            this.eSRPDataSet.Persoane.PlatesteCASSColumn.DefaultValue = true;
            this.eSRPDataSet.Persoane.PlatesteSomajColumn.DefaultValue = true;
            this.eSRPDataSet.Persoane.PlatesteImpozitColumn.DefaultValue = true;
            this.eSRPDataSet.Persoane.AreDeducereColumn.DefaultValue = true;
            this.eSRPDataSet.Persoane.MotivIncetareContractColumn.DefaultValue = String.Empty;




            eSRPDataSet.AngajatiSporuri.ValoareColumn.DefaultValue = 0;
            eSRPDataSet.AngajatiSporuri.ProcentColumn.DefaultValue = 0;
            eSRPDataSet.AngajatiSporuri.ValoarePreavizColumn.DefaultValue = 0;
            eSRPDataSet.AngajatiSporuri.CodUnitateColumn.DefaultValue = ModuleInfo.CodUnitate;


            /// contracte munca
            /// 
            this.eSRPDataSet.ContracteMunca.DataColumn.DefaultValue = DateTime.Now;
            this.eSRPDataSet.ContracteMunca.DeLaDataColumn.DefaultValue = DateTime.Now;
            this.eSRPDataSet.ContracteMunca.PerioadaDeterminataColumn.DefaultValue = false;

            ///Angajati - valori implicite
            this.eSRPDataSet.AngajatiSalarizare.IDDepartamentColumn.DefaultValue = 0;
            this.eSRPDataSet.AngajatiSalarizare.FractiuneNormaColumn.DefaultValue = 1.00;
            this.eSRPDataSet.AngajatiSalarizare.OreNormaColumn.DefaultValue = 8;
            this.eSRPDataSet.AngajatiSalarizare.NormaBazaColumn.DefaultValue = false;
            this.eSRPDataSet.AngajatiSalarizare.ServiciiPeChitantaColumn.DefaultValue = false;
            this.eSRPDataSet.AngajatiSalarizare.SalarColumn.DefaultValue = 0;
            this.eSRPDataSet.AngajatiSalarizare.DeLaDataColumn.DefaultValue = DateTime.Now;
            this.eSRPDataSet.AngajatiSalarizare.PanaLaDataColumn.DefaultValue = DBNull.Value;
            this.eSRPDataSet.AngajatiSalarizare.VechimeSporAniColumn.DefaultValue = 0;
            this.eSRPDataSet.AngajatiSalarizare.VechimeSporLuniColumn.DefaultValue = 0;
            ///valoarea implicita se seteaza in functia Setup
            //this.eSRPDataSet.AngajatiSalarizare.IdTipGradColumn.

            this.eSRPDataSet.AngajatiSalarizare.CodUnitateColumn.DefaultValue = ModuleInfo.CodUnitate;
            this.eSRPDataSet.AngajatiSalarizare.ClasaColumn.DefaultValue = 0;
            this.eSRPDataSet.AngajatiSalarizare.SalarFunctieColumn.DefaultValue = 0;

            this.eSRPDataSet.SituatieMilitara.DataLuatEvidentaColumn.DefaultValue = DateTime.Now;
            this.eSRPDataSet.SituatieMilitara.DataScoatereEvidentaColumn.DefaultValue = DateTime.Now;


     
 


            
            ActiveControl = numePrenumeTB;
            HandleSalvare += new EventHandler(Salvare);
            if (PersoanaSelectata != -1)
            {
                persoaneBindingSource.Filter = "IDpersoana=" + PersoanaSelectata.ToString();
            }
        }

        void Adapter_RowUpdated(object sender, SqlRowUpdatedEventArgs args)
        {
            if (args.Errors != null)
                throw args.Errors;
            if (args.StatementType == StatementType.Insert)
            {
                foreach (DataRow row in
                    eSRPDataSet.AngajatiSporuri.Select("IDAngajatSalarizare=" + args.Row["IDAngajatSalarizare", DataRowVersion.Original].ToString(),
                        "IDAngajatSalarizare", DataViewRowState.Added))
                {
                    row["IDAngajatSalarizare"] = args.Row["IDAngajatSalarizare"];
                }

            }
        }

        void bind_Format(object sender, System.Windows.Forms.ConvertEventArgs e)
        {
            // e.Value is the object value, we format it to be what we want to show up in the control
            System.Windows.Forms.Binding b = sender as System.Windows.Forms.Binding;
            if (b == null)
                return;
            RelationTextBox.DateTimePicker dtp = (b.Control as RelationTextBox.DateTimePicker);
            if (dtp == null)
            {
                MyTrace("Controlul " + b.Control.Name.ToString() + "  nu e de tipul RelationTextBox.DateTimePicker!");
                return;
            }
            if (e.Value == null || e.Value == DBNull.Value )
            {
                //dtp.ShowCheckBox = true;
                //dtp.Checked = false;
                //e.Value = dtp.Value;
                dtp.Value = dtp.NullDate;
            }
            /*else
            {
                dtp.ShowCheckBox = true;
                dtp.Checked = true;
            }*/

        }
        /// <summary>
        /// citeste setarile din ResUmaSetup
        /// </summary>
        /// <param name="sqlConn"></param>
        private void Setup(SqlConnection sqlConn)
        { 
            Object ret = GetSetupValue("ResUmaSetup", "AnulCurent", ModuleInfo.CodUnitate, sqlConn);
            /// nu a fost configurat modulul
            /// 
            while (ret == null)
            {
                MessageBox.Show("Modulul Resurse Umane nu a fost configurat. \nVa rugam sa-l configurati!",
                        "Eroare",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Hand);
                ResUmaSetupFrm frm = new ResUmaSetupFrm(ModuleInfo);
                frm.ShowDialog();
                ret = GetSetupValue("ResUmaSetup", "AnulCurent", ModuleInfo.CodUnitate, sqlConn);
            }
            AnulCurent = (Int16)ret;
            ret = GetSetupValue("ResUmaSetup", "LunaCurenta", ModuleInfo.CodUnitate, sqlConn);
            LunaCurenta = (Int16)ret;
            //angajatiBindingSource.Filter = "[Luna]=" + LunaCurenta.ToString() + "  AND [Anul]=" + AnulCurent.ToString();

            ret = GetSetupValue("ResUmaSetup", "Contracte", ModuleInfo.CodUnitate, sqlConn);
            FolosesteContracte = Convert.ToInt16(ret)!=0;

            ret = GetSetupValue("ResUmaSetup", "SituatieMilitara", ModuleInfo.CodUnitate, sqlConn);
            FolosesteSituatieMilitara = Convert.ToInt16(ret) != 0;



            SqlCommand cmd = new SqlCommand("select TOP 1 [IDOcupatie] from [Ocupatii] where len([CorOcupatie])=6", DeschideConexiune(workConnString));
            ret = cmd.ExecuteScalar();
            if (ret != null)
            {
                IDOcupatieImplicita = Convert.ToInt32(ret);
            }
            this.eSRPDataSet.ContracteMunca.IDOcupatieColumn.DefaultValue = IDOcupatieImplicita;

            //private int  = 0;
            //private int  = 0;
            cmd.CommandText = "select TOP 1 [TipContract] from [TipContracte]";
            ret = cmd.ExecuteScalar();
            if (ret != null)
            {
                IDTipContractImplicit = Convert.ToInt32(ret);
            }
            cmd.CommandText = "select TOP 1 [IDTipGrad] from [TipGrad]";
            ret = cmd.ExecuteScalar();
            if (ret != null)
            {
                IDTipGradImplicit = Convert.ToInt32(ret);
            }
            cmd.CommandText = "select TOP 1 [IDCasaAsigSanatate] from [CaseAsigurariSanatate]";
            ret = cmd.ExecuteScalar();
            if (ret != null)
            {
                IDCasaAsigurariSanatateImplicit = Convert.ToInt32(ret);
            }

            cmd.CommandText = "select TOP 1 [IDDepartament] from [Departamente] where CodUnitate="+ModuleInfo.CodUnitate;
            ret = cmd.ExecuteScalar();
            if (ret != null)
            {
                IDDepartamentImplicit = Convert.ToInt32(ret);
            }
            InchideConexiune(cmd.Connection);
            this.eSRPDataSet.ContracteMunca.TipGradColumn.DefaultValue = IDTipGradImplicit;
            this.eSRPDataSet.ContracteMunca.SalarIncadrareColumn.DefaultValue = 0;
            this.eSRPDataSet.ContracteMunca.OreNormaColumn.DefaultValue = 8;
            this.eSRPDataSet.ContracteMunca.FractiuneNormaColumn.DefaultValue = 1;


            this.eSRPDataSet.AngajatiSalarizare.IdTipGradColumn.DefaultValue = IDTipGradImplicit;
            eSRPDataSet.AngajatiSporuri.LunaColumn.DefaultValue = LunaCurenta;
            eSRPDataSet.AngajatiSporuri.AnulColumn.DefaultValue = AnulCurent;
            eSRPDataSet.AngajatiSporuri.DeLaDataColumn.DefaultValue = new DateTime(AnulCurent,LunaCurenta,1);
            SetInfoLunaAnul(LunaCurenta.ToString() + "," + AnulCurent.ToString());

        }

        override public void Cauta(object sender, EventArgs e)
        {
            EnableMainSearchButton = false;
            CautaPersonalFrm frm = new CautaPersonalFrm(ModuleInfo);
            if (frm.ShowDialog() == DialogResult.OK)
            {
                if (frm.Filtru == String.Empty)
                    return;
                //documenteBindingSource.Filter = frm.Filtru;
                persoaneBindingSource.Filter = frm.Filtru;

            }
            else
                persoaneBindingSource.Filter = String.Empty;
            EnableMainSearchButton = true;
        }

        private void PersonalFrm_Load(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            //persoaneBindingSource.Sort = "NumePrenume";
            //fara sortare ca la modificare il arunca la sfarsit

            AddBindingSource(persoaneBindingSource);//0
            listTableAdaptor.Add(this.persoaneTableAdapter.Adapter);
    
            AddBindingSource(angajatiOcupatiiBindingSource);//1
            listTableAdaptor.Add(angajatiOcupatiiTableAdapter.Adapter);

            AddBindingSource(fKAngajatiSalarizarePersoaneBindingSource);//2
            listTableAdaptor.Add(angajatiSalarizareTableAdapter.Adapter);

            if (FolosesteSituatieMilitara)
            {
                AddBindingSource(situatieMilitaraBindingSource);//3
                listTableAdaptor.Add(this.situatieMilitaraTableAdapter.Adapter);
            }

            AddBindingSource(fKAngajatiSporuriAngajatiSalarizareBindingSource);// fara numar adaugare in grid
            listTableAdaptor.Add(angajatiSporuriTableAdapter.Adapter);
 
            SqlConnection con = DeschideConexiune(workConnString);

            Object ret = GetSetupValue("ResUmaSetup", "VersiuneCOR", ModuleInfo.CodUnitate, con);
            Int16 versiuneCOR = Convert.ToInt16(ret);

            this.tipSporTableAdapter.Connection = con;
            this.tipSporTableAdapter.FillByActiv(this.eSRPDataSet.TipSpor);
            this.jurnaleTableAdapter.Connection = con;
            this.jurnaleTableAdapter.Fill(this.eSRPDataSet.Jurnale);
            this.eDocumentTipTableAdapter.Connection = con;
            this.eDocumentTipTableAdapter.Fill(this.eSRPDataSet.eDocumentTip);
            this.caseAsigurariSanatateTableAdapter.Connection = con;
            this.tipStudiiTableAdapter.Connection = con;
            this.tipStudiiTableAdapter.Fill(this.eSRPDataSet.TipStudii);
            this.caseAsigurariSanatateTableAdapter.Fill(this.eSRPDataSet.CaseAsigurariSanatate);
            this.localitatiTableAdapter.Connection = con;
            this.localitatiTableAdapter.Fill(this.eSRPDataSet.Localitati);
            this.ocupatiiTableAdapter.Connection = con;
            this.ocupatiiTableAdapter.FillByTerminalVersiune(this.eSRPDataSet.Ocupatii,versiuneCOR);
            this.tipContracteTableAdapter.Connection = con;
            this.tipContracteTableAdapter.Fill(this.eSRPDataSet.TipContracte);
            this.tipGradTableAdapter.Connection = con;
            this.tipGradTableAdapter.Fill(this.eSRPDataSet.TipGrad);
            if (FolosesteSituatieMilitara)
            {
                this.tipStareMilitaraTableAdapter.Connection = con;
                this.tipStareMilitaraTableAdapter.Fill(this.eSRPDataSet.TipStareMilitara);
                this.tipGradMilitarTableAdapter.Connection = con;
                this.tipGradMilitarTableAdapter.Fill(this.eSRPDataSet.TipGradMilitar);
            }

            SetCurentUnit(ModuleInfo.CodUnitate);
            AddButton("Calcul Salariu", global::ERPStudio.Properties.Resources._001_39, RecalculareSporuriModificate, ToolStripItemAlignment.Right, true);
            //AddButton("Scanari", global::ERPStudio.Properties.Resources._001_37, Scanari, ToolStripItemAlignment.Left, true);
            AddButton("Intreruperi CM", global::ERPStudio.Properties.Resources._001_16, SuspendareCM, ToolStripItemAlignment.Right, true);
            AddButton("Salveaza", global::ERPStudio.Properties.Resources.salvare1, Salvare, ToolStripItemAlignment.Right, true);
            InchideConexiune(con);
            Cursor.Current = Cursors.Default;
        }

        private void SuspendareCM(object sender, EventArgs e)
        {
            DataRowView drr = ((DataRowView)persoaneBindingSource.Current);
            if (drr == null || drr.IsNew)
            {
                MessageBox.Show("Va rugam sa finalizati adaugarea persoanei inainte de a trece la celelalte sectiuni ale machetei!\n",
                   "Stop",
                   MessageBoxButtons.OK,
                   MessageBoxIcon.Stop);
                return;
            }
            ESRPDataSet.PersoaneRow drrv = drr.Row as ESRPDataSet.PersoaneRow;
            PerioadeSuspendareFrm frm = new PerioadeSuspendareFrm(ModuleInfo, drrv.IdPersoana,drrv.NumePrenume);
            //frm.MdiParent = this.MdiParent;
            frm.ShowDialog();
            SqlCommand cmdS = new SqlCommand("resuma_GetLuniSuspendare", DeschideConexiune(workConnString));
            cmdS.CommandType = CommandType.StoredProcedure;
            cmdS.Parameters.Add(new SqlParameter("@IDPersoana", drrv.IdPersoana));
            cmdS.Parameters.Add(new SqlParameter("@LuniSusp", 0));
            cmdS.Parameters["@LuniSusp"].Direction = ParameterDirection.Output;
            cmdS.ExecuteNonQuery();
            LuniSuspendare = 0;
            if (cmdS.Parameters["@LuniSusp"].Value!=DBNull.Value)
                LuniSuspendare = Convert.ToInt32(cmdS.Parameters["@LuniSusp"].Value);
            InchideConexiune(cmdS.Connection);
        }

        private void cnpMTB_Leave(object sender, EventArgs e)
        {
            cnpMTB.Text = cnpMTB.Text.Trim();
            cnpMTB.Text = cnpMTB.Text.Replace(" ",String.Empty);
            if (cnpMTB.Text.Length < 13)
            {
                MessageBox.Show("CNP-ul are 13 caractere!.\n Va rugam introduceti valoare completa.",
                        "Info",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Information);
                return;
            }

            String sex = cnpMTB.Text.Substring(0,1);
            Int16 anul = Convert.ToInt16(cnpMTB.Text.Substring(1, 2));
            Int16 luna = Convert.ToInt16(cnpMTB.Text.Substring(3, 2));
            Int16 ziua = Convert.ToInt16(cnpMTB.Text.Substring(5, 2));
            Int16 sexVal = Convert.ToInt16(sex);
            if (sexCB.Items.Count!=0)
                if ((sexVal % 2) == 1)
                {
                    sexCB.SelectedIndex = 0;          
                }
                else
                {
                    sexCB.SelectedIndex = 1;
                }
            this.eSRPDataSet.Persoane.SexColumn.DefaultValue = sexCB.SelectedIndex;
            switch (sexVal)
            { 
                case 1:
                case 2:
                    anul += 1900; 
                    break;
                case 3:
                case 4:
                    anul += 1800;
                    break;
                case 5:
                case 6:
                    anul += 2000;
                    break;
            }
            DateTime dataN = new DateTime(anul, luna, ziua);
            if (dataNasteriiDTP.Value != dataN)
                dataNasteriiDTP.Value = dataN;
            else
            {
                dataNasteriiDTP.Value = new DateTime(1900, 1, 1);
                dataNasteriiDTP.Value = dataN;
            }
            
            //this.eSRPDataSet.Persoane.DataNasteriiColumn.DefaultValue = dataN;
        }

        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            SetTitle();
           
            if (PersonalTC.SelectedTab == PersoaneTP)
            {
                IndexSetCurent = 0;
                ActiveControl = numePrenumeTB;
                return;
            }
            if (PersonalTC.SelectedTab == OcupatiiSpecTP)
            {
                IndexSetCurent = 1;
                ActiveControl = angajatiOcupatiiDGV;
                return;
            }
            if (PersonalTC.SelectedTab == AngajatTP)
            {
                ActiveControl = marcaTB;
                IndexSetCurent = 2;
                return;
            }

            if (PersonalTC.SelectedTab == DocumenteTP)
            {
                ESRPDataSet.PersoaneRow pRow = ((DataRowView)persoaneBindingSource.Current).Row as ESRPDataSet.PersoaneRow;
                SqlConnection sqlCon = DeschideConexiune(workConnString);
                this.resuma_eDocumentePersoanaTableAdapter.Connection = sqlCon;
                this.resuma_eDocumentePersoanaTableAdapter.FillByPersoana(this.eSRPDataSet.resuma_eDocumentePersoana,pRow.IdPersoana);
                InchideConexiune(sqlCon);
            }
            

            if (PersonalTC.SelectedTab == SituatieMilitaraTP)
            {
                DataRowView dr = persoaneBindingSource.Current as DataRowView;
                situatieMilitaraTableAdapter.Connection = DeschideConexiune(workConnString);
                situatieMilitaraTableAdapter.FillByPersoana(this.eSRPDataSet.SituatieMilitara, Convert.ToInt32(dr["IdPersoana"]));
                InchideConexiune(situatieMilitaraTableAdapter.Connection);
                this.eSRPDataSet.SituatieMilitara.IdPersoanaColumn.DefaultValue = Convert.ToInt32(dr["IdPersoana"]);
                IndexSetCurent = 3;
                if (situatieMilitaraBindingSource.Count == 0)
                {
                    situatieMilitaraBindingSource.AllowNew = true;
                    Adauga(this, null);
                    eSRPDataSet.SituatieMilitara.DataLuatEvidentaColumn.DefaultValue = DateTime.Now;
                    situatieMilitaraBindingSource.AllowNew = false;
                }
                ActiveControl = GradMilitarCB;
            }

           
        }

        private void tabControl1_Selecting(object sender, TabControlCancelEventArgs e)
        {
            DataRowView dr = ((DataRowView)persoaneBindingSource.Current);
            if ((dr !=null) && dr.IsNew)
            {
                e.Cancel = true;
                MessageBox.Show("Va rugam sa finalizati adaugarea persoanei inainte de a trece la celelalte sectiuni ale machetei!\n",
                    "Stop",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Stop);
                return;
            }

            //daca se incearca selectarea datelor angajatului inainte de adaugarea contractului
            if (e.TabPage == AngajatTP || e.TabPage == SituatieMilitaraTP)
            {

                if (eSRPDataSet.Persoane.Rows.Count == 0 || persoaneBindingSource.Count==0)
                {
                    e.Cancel = true;
                    MessageBox.Show("Va rugam sa selectati o persoana inainte de a adauga date despre angajat!\nPentru adaugarea unei persoane selectati tabul 'General'.",
                        "Info",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Stop);
                    return;
                }

            }

        }

        override public void SetCurentMonth(short vCodUnitate)
        {
            SqlConnection conn = DeschideConexiune(workConnString);
            Setup(conn);
            InchideConexiune(conn);
        }

        override public void SetCurentUnit(short vCodUnitate)
        {
            Cursor.Current = Cursors.WaitCursor;
            SqlConnection con = DeschideConexiune(workConnString);
            try
            {
                this.departamenteTableAdapter.Connection = con;
                this.departamenteTableAdapter.Fill(this.eSRPDataSet.Departamente, vCodUnitate);
                this.persoaneTableAdapter.Connection = con;
                this.persoaneTableAdapter.FillByCodUnitate(this.eSRPDataSet.Persoane, vCodUnitate);
                this.angajatiSalarizareTableAdapter.Connection = con;
                this.angajatiSalarizareTableAdapter.Fill(this.eSRPDataSet.AngajatiSalarizare,ModuleInfo.CodUnitate);
                this.angajatiOcupatiiTableAdapter.Connection = con;
                this.angajatiOcupatiiTableAdapter.Fill(this.eSRPDataSet.AngajatiOcupatii);
                this.angajatiSporuriTableAdapter.Connection = con;
                this.angajatiSporuriTableAdapter.Fill(this.eSRPDataSet.AngajatiSporuri,ModuleInfo.CodUnitate);
                PersoaneTP.Select();
                Setup(con);
            }
            catch(Exception ex)
            {
                TrateazaExceptie(ex);
            }
            InchideConexiune(con);
            fKAngajatiSporuriAngajatiSalarizareBindingSource.Sort = "OrdineSpor";
            SetTitle();
            if (eSRPDataSet.Persoane.Count == 0)
                Adauga(this, null);
            Cursor.Current = Cursors.Default;
            if (!FolosesteSituatieMilitara)
                PersonalTC.TabPages.Remove(SituatieMilitaraTP);

        }

        private void numePrenumeTB_Validating(object sender, CancelEventArgs e)
        {
            ((TextBox)sender).Text = ((TextBox)sender).Text.ToUpper();
        }

        private void RecalculareSporuriModificate(object sender, EventArgs args)
        {
            ESRPDataSet.PersoaneRow drPers = ((DataRowView)persoaneBindingSource.Current).Row as ESRPDataSet.PersoaneRow;
            if (drPers.RowState == DataRowState.Detached)
            {
                MessageBox.Show("Salvati informatiile persoanei curente si apoi folositi functia de recalcul salarii!",
                "Eroare",
                MessageBoxButtons.OK,
                MessageBoxIcon.Stop);
                return;
            }
            SqlConnection Connection = DeschideConexiune(workConnString);
            //determina suspendarea
            SqlCommand cmdS = new SqlCommand("resuma_CalculSalarii", Connection);
            cmdS.CommandType = CommandType.StoredProcedure;
            cmdS.Parameters.Add(new SqlParameter("@_Anul", AnulCurent));
            cmdS.Parameters.Add(new SqlParameter("@_Luna", LunaCurenta));
            cmdS.Parameters.Add(new SqlParameter("@_CodUnitate", ModuleInfo.CodUnitate));
            cmdS.Parameters.Add(new SqlParameter("@_IDPersoanaSelectata", drPers.IdPersoana));
            cmdS.ExecuteNonQuery();

            InchideConexiune(Connection);
            SetStatus("Recalcul efectuat!");
        }

        override public void Salvare(object sender, EventArgs args)
        {
            ///modifica userul celui care face modificarea
            DataRow[] updatedRows =  eSRPDataSet.Persoane.Select(null, null, DataViewRowState.ModifiedCurrent);
            if (updatedRows.Length != 0)
            {
                foreach (DataRow dr in updatedRows)
                    dr["UserID"] = ModuleInfo.UserID;
            }
           
            base.Salvare(sender, args);
            if (EroareSalvare)
                return;
            ///incarca tabelele care s-au modificat
            ///
            SqlConnection con = DeschideConexiune(workConnString);
            this.angajatiSporuriTableAdapter.Connection = con;
            this.angajatiSporuriTableAdapter.Fill(this.eSRPDataSet.AngajatiSporuri, ModuleInfo.CodUnitate);
            InchideConexiune(con);
        }
       

        private void nrCutieCMTextBox_Leave(object sender, EventArgs e)
        {
            SqlCommand cmd = new SqlCommand("SELECT Count(*) FROM [Persoane] WHERE [NrCutieCM]='" + nrCutieCMTextBox.Text + "' and [CodUnitate]=" + ModuleInfo.CodUnitate,DeschideConexiune(workConnString));
            Object ret = cmd.ExecuteScalar();
            InchideConexiune(cmd.Connection);
            if (ret != null && ret != DBNull.Value)
            {
                if (Convert.ToInt16(ret) >= 50)
                {
                    MessageBox.Show("Aveti deja " + ret.ToString() + " carnete in cutia " + nrCutieCMTextBox.Text,
                    "Eroare",
                    MessageBoxButtons.OK,
                    MessageBoxIcon.Stop);
                }
            }
        }

        private void persoaneBindingSource_CurrentChanged(object sender, EventArgs e)
        {
            SetTitle();
            if (persoaneBindingSource.Current == null)
                return;
            ESRPDataSet.PersoaneRow drPers = ((DataRowView)persoaneBindingSource.Current).Row as ESRPDataSet.PersoaneRow;
            SqlConnection Connection = DeschideConexiune(workConnString);
            //determina suspendarea
            SqlCommand cmdS = new SqlCommand("resuma_GetLuniSuspendare", Connection);
            cmdS.CommandType = CommandType.StoredProcedure;
            cmdS.Parameters.Add(new SqlParameter("@IDPersoana", drPers.IdPersoana));
            cmdS.Parameters.Add(new SqlParameter("@LuniSusp", 0));
            cmdS.Parameters["@LuniSusp"].Direction = ParameterDirection.Output;
            cmdS.ExecuteNonQuery();
            LuniSuspendare = 0;
            eSRPDataSet.AngajatiSporuri.IdPersoanaColumn.DefaultValue = drPers.IdPersoana;
            if (cmdS.Parameters["@LuniSusp"].Value!=DBNull.Value)
                LuniSuspendare = Convert.ToInt32(cmdS.Parameters["@LuniSusp"].Value);

            if (PersonalTC.SelectedTab == OcupatiiSpecTP || PersonalTC.SelectedTab == PersoaneTP)
            {
                InchideConexiune(Connection);
                return;
            }
            
            if (PersonalTC.SelectedTab == AngajatTP)
            {
                ActiveControl = marcaTB;
            }
            
            if (PersonalTC.SelectedTab == SituatieMilitaraTP)
            {
                situatieMilitaraTableAdapter.Connection = Connection;
                if ((drPers != null))
                {
                    this.situatieMilitaraTableAdapter.FillByPersoana(eSRPDataSet.SituatieMilitara, drPers.IdPersoana);
                }
            }
            //InchideConexiune(contracteMuncaTableAdapter.Connection);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            angajatiOcupatiiBindingSource.RemoveCurrent();
        }

        private void dataVechimeMuncaDateTimePicker_ValueChanged(object sender, EventArgs e)
        {

            Decimal luni = (DateTime.Now.Year * 12 + DateTime.Now.Month) - 
                (dataVechimeMuncaDTP.Value.Year * 12 + dataVechimeMuncaDTP.Value.Month);
             if (luni < 0)
             {
                 vechimeMuncaAniNUD.Value = 0;
                 vechimeMuncaLuniNUD.Value = 0;
                 //MessageBox.Show("Data inceperii activitatii incorecta!");
                 return;
             }
             luni -= LuniSuspendare;
             if (luni < 0)
             {
                 vechimeMuncaAniNUD.Value = 0;
                 vechimeMuncaLuniNUD.Value = 0;
                 //MessageBox.Show("Suspendare mai mare decat perioada de activitate!");
                 return;
             }
             vechimeMuncaAniNUD.Value = Math.Floor(luni / 12);
             vechimeMuncaLuniNUD.Value = luni % 12;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (nrCutieCMTextBox.Text == String.Empty)
                return;
            SqlCommand cmd = new SqlCommand("SELECT MAX(PozCutieCM)+1 FROM [Persoane] WHERE [NrCutieCM]=" + nrCutieCMTextBox.Text + " AND [CodUnitate]=" + ModuleInfo.CodUnitate,
                DeschideConexiune(workConnString));
            Decimal next = Convert.ToDecimal(cmd.ExecuteScalar());
            pozCutieCMNUD.Value = next;
            InchideConexiune(cmd.Connection);
        }

        private void sporuriDataGridView_CellLeave(object sender, DataGridViewCellEventArgs e)
        {
            RelationTextBox.DataGridview dg = sender as RelationTextBox.DataGridview;
            if (fKAngajatiSalarizarePersoaneBindingSource.Current == null)
                return;

            ESRPDataSet.AngajatiSalarizareRow asRow = ((DataRowView)fKAngajatiSalarizarePersoaneBindingSource.Current).Row as ESRPDataSet.AngajatiSalarizareRow;
            if (e.ColumnIndex == idTipSporColumn.Index)
            {
                ComboBox cbTip = dg.EditingControl as ComboBox;
                if (cbTip!=null && cbTip.SelectedItem != null)
                {
                    ESRPDataSet.TipSporRow tsrd = ((DataRowView)cbTip.SelectedItem).Row as ESRPDataSet.TipSporRow;
                    if (tsrd.Format.Contains("S"))
                    {
                        if (dg[valoareColumn.Index, e.RowIndex].Value == DBNull.Value || Convert.ToDecimal(dg[valoareColumn.Index, e.RowIndex].Value) == Decimal.Zero)
                            dg[valoareColumn.Index, e.RowIndex].Value = tsrd.Valoare;
                        dg[procentColumn.Index, e.RowIndex].Value = Decimal.Zero;
                        dg[procentColumn.Index, e.RowIndex].ReadOnly = true;
                        dg[procentColumn.Index, e.RowIndex].Style.BackColor = Color.LightGray;
                        dg[valoareColumn.Index, e.RowIndex].Style.BackColor = Color.White;
                    }
                    //sporuriDataGridView[valoarePreavizColumn.Index, e.RowIndex].Value = tsrd.Valoare;
                    if (tsrd.Format.Contains("P"))
                    {
                        if (dg[procentColumn.Index, e.RowIndex].Value==DBNull.Value || Convert.ToDecimal(dg[procentColumn.Index, e.RowIndex].Value) == Decimal.Zero)
                            dg[procentColumn.Index, e.RowIndex].Value = tsrd.Valoare;
                        dg[valoareColumn.Index, e.RowIndex].Value = Decimal.Zero;
                        dg[valoareColumn.Index, e.RowIndex].ReadOnly = true;
                        dg[valoareColumn.Index, e.RowIndex].Style.BackColor = Color.LightGray;
                        dg[procentColumn.Index, e.RowIndex].Style.BackColor = Color.White;

                    }

                    if (tsrd.Format.Contains("G"))
                    {
                        SqlConnection con = DeschideConexiune(workConnString);
                        SqlCommand cmdS = new SqlCommand("resuma_GetProcentGrila", con);
                        cmdS.CommandType = CommandType.StoredProcedure;
                        cmdS.Parameters.Add(new SqlParameter("@IDAngajatSalarizare", asRow.IDAngajatSalarizare));
                        cmdS.Parameters.Add(new SqlParameter("@IDTipSpor", tsrd.IdTipSpor));
                        cmdS.Parameters.Add(new SqlParameter("@Procent", 0));
                        cmdS.Parameters["@Procent"].Direction = ParameterDirection.Output;
                        cmdS.ExecuteNonQuery();
                        InchideConexiune(con);
                        Decimal procent = 0;
                        if (cmdS.Parameters["@Procent"].Value != DBNull.Value)
                            procent = Convert.ToDecimal(cmdS.Parameters["@Procent"].Value);

                        dg[procentColumn.Index, e.RowIndex].Value = procent;
                        dg[valoareColumn.Index, e.RowIndex].Value = Decimal.Zero;
                        dg[valoareColumn.Index, e.RowIndex].ReadOnly = true;
                        dg[procentColumn.Index, e.RowIndex].ReadOnly = true;
                        dg[valoareColumn.Index, e.RowIndex].Style.BackColor = Color.LightGray;
                        dg[procentColumn.Index, e.RowIndex].Style.BackColor = Color.LightGray;

                    }



                }
 
            }
        }

        private void dataVechimeMuncaDTP_Validating(object sender, CancelEventArgs e)
        {
            DateTime ultimazi = new DateTime(AnulCurent,LunaCurenta,1);
            ultimazi = ultimazi.AddMonths(1).AddDays(-1);
            if (dataVechimeMuncaDTP.Value > ultimazi)
            {
                MessageBox.Show("Data de la care se calculeaza vechimea in munca trebuie sa fie anterioara lunii curente!","Eroare",MessageBoxButtons.OK,MessageBoxIcon.Stop);
                e.Cancel = true;
                return;
            }
        }

        override public void toolStripLabelAnLuna_Click(object sender, EventArgs e)
        {
            ResUmaSetupFrm frm = new ResUmaSetupFrm(ModuleInfo);
            frm.ShowDialog();            
        }

        private void SpecialitatilinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            ESRPDataSet.PersoaneRow dr = ((DataRowView)persoaneBindingSource.Current).Row as ESRPDataSet.PersoaneRow;
            SpecialitatiFrm frm = new SpecialitatiFrm(ModuleInfo,dr.IdPersoana,dr.NumePrenume);
            frm.MdiParent = this.MdiParent;
            frm.Show();
        }

        private void resumaeDocumentePersoanaBindingSource_CurrentChanged(object sender, EventArgs e)
        {
            if (resumaeDocumentePersoanaBindingSource.Current == null)
                return;
            Cursor.Current = Cursors.AppStarting;
            ESRPDataSet.resuma_eDocumentePersoanaRow pRow = ((DataRowView)resumaeDocumentePersoanaBindingSource.Current).Row as ESRPDataSet.resuma_eDocumentePersoanaRow;
            SqlConnection sqlCon = DeschideConexiune(workConnString);
            this.eDocumentPageTableAdapter.Connection = sqlCon;
            this.eDocumentPageTableAdapter.FillByDocument(this.eSRPDataSet.eDocumentPage,pRow.IDDocument);
            InchideConexiune(sqlCon);
            Cursor.Current = Cursors.Default;
        }

        private void eDocumentPageBindingSource_CurrentChanged(object sender, EventArgs e)
        {
            if (eDocumentPageBindingSource.Current == null)
                return;
            Cursor.Current = Cursors.AppStarting;
            ESRPDataSet.eDocumentPageRow pRow = ((DataRowView)eDocumentPageBindingSource.Current).Row as ESRPDataSet.eDocumentPageRow;
            if (pRow.RowState != System.Data.DataRowState.Detached && pRow.Continut != null)
            {
                MemoryStream ms = new MemoryStream(pRow.Continut);
                pictureBox1.Image = Image.FromStream(ms);
                bmp = pictureBox1.Image;
                if (bmp.Width > bmp.Height)
                {
                    ratio = (float)pictureBox1.Width / (float)bmp.Width;
                    translateRatio = (float)bmp.Width / (float)pictureBox1.Width;

                }
                else
                {
                    ratio = (float)pictureBox1.Height / (float)bmp.Height;
                    translateRatio = (float)bmp.Height / (float)pictureBox1.Height;

                }

            }


        }

        private void toolStripMenuItem2_Click(object sender, EventArgs e)
        {
            pictureBox1.Width = 5000;
            pictureBox1.Height = 4000;
        }

        private void pictureBox1_Paint(object sender, PaintEventArgs e)
        {
            //Conditions to avoid to proceed further.
            if (bmp == null) { return; }
            if (translateSet == false && zoomSet == false) { return; }

            Graphics g = e.Graphics;

            //Scale transform operation on the picture box device context
            //zoomFac is global variable which can be used to get desired zoom
            if(!float.IsInfinity(zoomFac))
                g.ScaleTransform(ratio * zoomFac, ratio * zoomFac);

            //move image to new position
            if (translateSet == true)
            {
                g.TranslateTransform(translateX, translateY);
            }

            //Drawback the bitmap to the transformed decive context

            //Apply double buffering (Draw to a bitmap first and then draw to picturebox) if
            // using large image and experience flickering
            g.Clear(Color.White);
            g.DrawImage(bmp, 0, 0);
 

        }

        private void PersonalFrm_Shown(object sender, EventArgs e)
        {
            //Draw the image initially
            //zoomSet = true;
            //pictureBox1.Refresh();
            //zoomSet = false;
        }

        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                translateSet = false;
                zoomSet = true;
                translate = false;
            }
            if (e.Button == System.Windows.Forms.MouseButtons.Right)
            {
                translateSet = true;
                zoomSet = false;
                translate = true;
            }

            transStartX = e.X;
            transStartY = e.Y;
            Cursor = Cursors.Arrow;

        }

        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            //If mouse down is true
            if (translate == true)
            {
                //calculate the total distance to move from 0,0
                //previous image position+ current moving distance
                translateX = curImageX + ((e.X - transStartX) * (translateRatio / zoomFac));
                translateY = curImageY + ((e.Y - transStartY) * (translateRatio / zoomFac));
                //call picturebox to update the image in the new position
            }
            if (zoomSet)
            {
                if (e.X > transStartX)
                    zoomFac += e.X / transStartX;
                if (e.X < transStartX)
                    zoomFac -= e.X / transStartX;

            }
            pictureBox1.Refresh();
            //set mouse down operation end
            translate = false;
            //set present position of the image after move.
            curImageX = translateX;
            curImageY = translateY;
            Cursor = Cursors.Arrow;

        }

        
        private void panaLaDataAngajatDTP_Validating(object sender, CancelEventArgs e)
        {
            int i = 0;
            i++;
        }

       
        private void sporuriDataGridView_RowValidating(object sender, DataGridViewCellCancelEventArgs e)
        {
            RelationTextBox.DataGridview dg = sender as RelationTextBox.DataGridview;
            try
            {
                if (dg.CurrentRow == null || dg.CurrentRow.DataBoundItem == null ||
                    dg.CurrentRow.DataBoundItem.GetType() != typeof(DataRowView))
                    return;
            }
            catch(Exception ex)
            {
                MyTrace(ex.Message);
                return;
            }
            ESRPDataSet.AngajatiSporuriRow asr = ((DataRowView)dg.CurrentRow.DataBoundItem).Row as ESRPDataSet.AngajatiSporuriRow;
            if(asr!=null)
            {
                /// procentul si valoarea pot sa fie ambele diferite de 0;
                //if (asr.Procent == 0 && asr.Valoare == 0 && asr.RowState!= DataRowState.Unchanged)
                //{
                //    e.Cancel = true;
                //    MessageBoxFrm mbt = new MessageBoxFrm("Eroare validare", "Valoarea si procentul unui spor nu pot sa fie ambele egale cu 0!", String.Empty, MessageBoxFrm.ImaginiMB.StopIcon, null);
                //    mbt.AddButton("Ieşire", 70, mbt.MessageBoxFrm_Click_Yes);
                //    mbt.ShowDialog();
                //    return;
                //}
                if (asr.Procent != 0 && asr.Valoare != 0 && asr.RowState != DataRowState.Unchanged)
                {
                    e.Cancel = true;
                    MessageBoxFrm mbt = new MessageBoxFrm("Eroare validare", "Valoarea si procentul unui spor nu pot sa fie ambele diferite de 0!", String.Empty, MessageBoxFrm.ImaginiMB.StopIcon, null);
                    mbt.AddButton("Ieşire", 70, mbt.MessageBoxFrm_Click_Yes);
                    mbt.ShowDialog();
                    return;
                }
                DateTime acum=new DateTime(AnulCurent,LunaCurenta,1);
                //if (asr.DeLaData<acum && asr.RowState != DataRowState.Unchanged)
                //{
                //    e.Cancel = true;
                //    MessageBoxFrm mbt = new MessageBoxFrm("Eroare validare", "Data aplicarii sporului nu poate sa fie anterioara perioadei curente!", String.Empty, MessageBoxFrm.ImaginiMB.StopIcon, null);
                //    mbt.AddButton("Ieşire", 70, mbt.MessageBoxFrm_Click_Yes);
                //    mbt.ShowDialog();
                //    return;
                //}

                if (!asr.IsPanaLaDataNull() && asr.PanaLaData < acum && asr.RowState != DataRowState.Unchanged)
                {
                    e.Cancel = true;
                    MessageBoxFrm mbt = new MessageBoxFrm("Eroare validare", "Data pana la care se aplica sporul nu poate sa fie anterioara perioadei curente!", String.Empty, MessageBoxFrm.ImaginiMB.StopIcon, null);
                    mbt.AddButton("Ieşire", 70, mbt.MessageBoxFrm_Click_Yes);
                    mbt.ShowDialog();
                    return;
                }

            }

            int i = 0;
            i++;
        }

        private void sporuriDGV_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            RelationTextBox.DataGridview dg = sender as RelationTextBox.DataGridview;
            if (e.ListChangedType != ListChangedType.Reset || dg.Rows.Count <= 0)
                return;
            MyTrace(e.ListChangedType + "," + dg.Rows.Count.ToString());
            foreach (DataGridViewRow dc in dg.Rows)
            {
                String formatSpor = String.Empty;
                if (dc.Cells[FormatSporColumn.Index].Value != DBNull.Value && dc.Cells[FormatSporColumn.Index].Value != null)
                    formatSpor = dc.Cells[FormatSporColumn.Index].Value.ToString();


                if (formatSpor.Contains("S"))
                {
                    dg[procentColumn.Index, dc.Index].ReadOnly = true;                    
                    dg[procentColumn.Index, dc.Index].Style.BackColor = Color.LightGray;
                }
                if (formatSpor.Contains("P"))
                {
                    dg[valoareColumn.Index, dc.Index].ReadOnly = true;
                    dg[valoareColumn.Index, dc.Index].Style.BackColor = Color.LightGray;
                }
                if (formatSpor.Contains("G"))
                {
                    dg[valoareColumn.Index, dc.Index].ReadOnly = true;
                    dg[valoareColumn.Index, dc.Index].Style.BackColor = Color.LightGray;
                    dg[procentColumn.Index, dc.Index].ReadOnly = true;
                    dg[procentColumn.Index, dc.Index].Style.BackColor = Color.LightGray;
                }
            }
        }

        
    }
    [Serializable]
    public class SexSursa
    {
        public SexSursa(String nume, Int16 tag, String _type)
        {
            _Name = nume;
            _Tag = tag;
            _Type = _type;
        }

        private String _Name = String.Empty;
        [System.ComponentModel.Bindable(true)]
        public String Name
        {
            get
            {
                return _Name;
            }
            set
            {
                _Name = value;
            }
        }
        private Int16 _Tag = 0;
        [System.ComponentModel.Bindable(true)]
        public Int16 Tag
        {
            get
            {
                return _Tag;
            }
            set
            {
                _Tag = value;
            }
        }
        private String _Type = "T";
        [System.ComponentModel.Bindable(true)]
        public String Type
        {
            get
            {
                return _Type;
            }
            set
            {
                _Type = value;
            }
        }

    }
}
